package edu.gyc.hiseckill.code;

import edu.gyc.hiseckill.error.BusinessException;
import edu.gyc.hiseckill.model.UserOrder;
import edu.gyc.hiseckill.service.UserOrderService;
import lombok.extern.slf4j.Slf4j;

 @Slf4j
 public class OrderThread implements Runnable{

    private UserOrder userOrder;
    private UserOrderService userOrderService;



    public OrderThread(UserOrderService userOrderService) {
        UserOrder userOrder=new UserOrder();
        userOrder.setPromoId(1);
        userOrder.setAmount(1);
        userOrder.setUserId(10);
        userOrder.setItemId(4);
        this.userOrder=userOrder;
        this.userOrderService=userOrderService;
    }

    @Override
    public void run() {

        //高并发下还是会有重复
        try {
            userOrderService.createOrder(userOrder);
        } catch (BusinessException e) {
            e.printStackTrace();
        }
        log.info(Thread.currentThread().getName());

    }
}